﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = "_Layout";
}
<body class="layui-anim layui-anim-up">
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="/Admin/Admin/Index">首页</a>
            <a>
                <cite>分类管理</cite>
            </a>
        </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon" style="line-height:30px">ဂ</i>
        </a>
    </div>
    <div class="x-body">
        <xblock>
            <button class="layui-btn j-add"><i class="layui-icon"></i>添加</button>
        </xblock>
        <table class="layui-table" lay-data="{ url:'/Admin/Classify/GetClass', page:true, id:'class'}" lay-filter="class">
            <thead>
                <tr>
                    <th lay-data="{field:'', width:'7%', sort: true,type:'numbers'}">ID</th>
                    <th lay-data="{field:'Title', width:'15%'}">分类名</th>
                    <th lay-data="{field:'State', width:'13%',templet: '#barIsEnabled'}">状态</th>
                    <th lay-data="{field:'ImgUrl', width:'50%', templet: '#imgUrl'}">图片地址</th>
                    <th lay-data="{field:'' , width:'15%' , templet: '#barDemo'}">操作</th>
                </tr>
            </thead>
        </table>
        <script type="text/html" id="imgUrl">
            <a href="{{d.Ico}}" target="_blank">{{d.Ico}}</a>
        </script>
        <script type="text/html" id="barIsEnabled">
            {{#  if(d.State==1){ }}
            <input type="checkbox" checked="" lay-skin="switch" lay-text="启用|禁用" lay-filter="ChkIsEnableds" aid="{{ d.Id }}">
            {{#  }else{ }}
            <input type="checkbox" lay-skin="switch" lay-text="启用|禁用" lay-filter="ChkIsEnableds" aid="{{ d.Id }}">
            {{#  } }}
        </script>
        <script type="text/html" id="barDemo">
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        </script>
    </div>
    <script>layui.use(['laydate', 'table', 'form','layer'], function () {
            var laydate = layui.laydate;
            var table = layui.table;
            var $ = layui.jquery;
            var form = layui.form;
            var layer=layui.layer;

            //启用、禁用
            form.on('switch(ChkIsEnableds)', function (data) {
                var sw = this;
                var vn = sw.checked ? "启用" : "禁用";
                var vis = sw.checked ? true : false;
                var vcid = $(sw).attr("aid");
                var x = sw.checked;
                HsCms.Confirm("您确定" + vn + "该数据吗？", function () {
                    HsCms.AjaxPost("/Admin/Classify/IsEnabled", "Id=" + vcid + "&isEnabled=" + vis, function (result) {
                        if (result.code === 1) {
                            table.reload("class");
                        }
                        else {
                            sw.checked = !x;
                            form.render("checkbox");
                        }
                        HsCms.Msg(result.msg);
                    });
                }, function () {
                    sw.checked = !x;
                    form.render("checkbox");
                }, function () {
                    sw.checked = !x;
                    form.render("checkbox");
                });
            });

            //监听行工具事件
            table.on('tool(class)', function (obj) {
                var data = obj.data;
                //console.log(obj)
                if (obj.event === 'del') {
                    layer.confirm('真的删除行么', function (index) {

                        $.ajax({
                            type: "post",
                            url: "/Admin/Classify/Del",
                            data: { id: data.Id },
                            success: function (result) {
                                if (result.state == "OK") {
                                    layer.msg(result.msg)
                                } else {
                                    layer.msg(result.msg)
                                }
                            }
                        })

                        obj.del();

                    });
                } else if (obj.event === 'edit') {
                    layer.prompt({
                        formType: 2
                        , value: data.email
                    }, function (value, index) {
                        obj.update({
                            email: value
                        });
                        layer.close(index);
                    });
                }
            });

            $(".j-add").click(function () {
                //var langstr = langs.join(',');
                HsCms.OpenPart(2, 'bann', '/Admin/Classify/Add?type=add', "新增", ['700px', '400px'], ['新增', '取消'], function (layero) {

                }, function (index, layero) {
                    $(".btnEdit", layero.find("iframe")[0].contentWindow.document).click();
                });
            });


        });</script>
</body>